package core.gamestates;

import game.player.Player;
import game.scenario.Map;
import gui.GameImageLabel;
import gui.Menu;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import utils.Properties;
import core.Camera;
import core.GameFlow;
import core.GameState;

public class InGameState extends GameState {

	Map map;
	Menu interfaz;
	


	public InGameState() {
		super();
	
		map = new Map("mapaA");
		map.setPosition(0f, 0f);
		Rectangle camBounds = new Rectangle(0 , 0 , map.getWidth() ,map.getHeight());
		camBounds.setLocation((int)map.getX() ,(int) map.getY());
		Camera.getInstance().setBounds(camBounds);
		
		renderer.addElement(map);

		interfaz = new Menu();
		interfaz.addButtonListener(GameFlow.getInstance());
		interfaz.addButtonListener(map);

		interfaz.addCashLabel(400, 32, 120, 32);
		interfaz.addLivesLabel(520, 32, 120, 32);
		
		interfaz.addTowerSelectionPanel(0, 100, 6, 1);
		
		renderer.addElement(interfaz);
	}

	public Map getMap() {
		return map;
	}

	@Override
	public void reset() {
		// TODO Auto-generated method stub
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub
		map.setX(Camera.getInstance().getIntX());
		map.setY(Camera.getInstance().getIntY());
		map.updateLogic();
		if (Player.getInstance().getLives() <= 0) {
			GameFlow.getInstance().doAction(GameFlow.SWITCH_TO_GAME_OVER_STATE);
		}
	}

	@Override
	public boolean onClick(MouseEvent m) {
		boolean b = false;
		// TODO Auto-generated method stub
		b = interfaz.onClick(m);
		if (!b) {
			b = map.onClick(m);
		}
		return b;
	}

	@Override
	public void onKeyPresed(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateMouse(Point p) {
		
		// TODO Auto-generated method stub
		interfaz.updateMouse(p);
		map.updateMouse(p);
	}

}
